<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100的整数">
<input type="button" value="猜一猜" onclick="f()">
<h3>
    结果:<span></span>
</h3>
<script>
    let x=parseInt(Math.random()*100)+1;
    console.log(x);
    let i=document.querySelector("input");
    let s=document.querySelector("span");
    let times=0;
    function f() {
        times+=1;
        if(isNaN(i.value)){
            s.innerText="输入错误!";
            return;
        }
        if(i.value>x){
            s.innerText="猜大了!";
        }else if(i.value<x){
            s.innerText="猜小了!";
        }else{
            s.innerText="恭喜你在第"+times+"次猜对了!";
        }
    }
</script>
</body>
</html>